//
//  HWLevelView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/19.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWLevelView.h"
#import "HWLevelCell.h"

@interface HWLevelView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, copy)NSArray *arr;
@end

@implementation HWLevelView

- (NSArray *)arr
{
    if (!_arr)
    {
        _arr = [[NSArray alloc]init];
    }
    return _arr;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
    }
    return _tableView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.tableView];
    }
    return self;
}

#pragma mark - tableView delegate datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60*kUIScaleBasePlus;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40*kUIScaleBasePlus;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,40*kUIScaleBasePlus)];
    footView.backgroundColor = LCHexColor(0xF5F5F5);
    
    UILabel *titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(20*kUIScaleBasePlus,17*kUIScaleBasePlus,80*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft
                                                 textClor:LCHexColor(0xD4D4D4)
                                                 textFont:16*kUIScaleBasePlus];
    titleLabel.text = @"排名";
    [footView addSubview:titleLabel];
    
    UILabel *moneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH-35*kUIScaleBasePlus-120*kUIScaleBasePlus,16*kUIScaleBasePlus,120*kUIScaleBasePlus,15*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentRight
                                                 textClor:LCHexColor(0xD4D4D4)
                                                 textFont:16*kUIScaleBasePlus];
    moneyLabel.text = @"累计收益(元)";
    [footView addSubview:moneyLabel];
    
    return footView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWLevelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWLevelCell"];
    
    if (!cell)
    {
        cell = [[HWLevelCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HWLevelCell"];
        cell.selectionStyle = 0;
    }
    
    HWLevelModel *model = [[HWLevelModel alloc]initWithDic:self.arr[indexPath.row]];
    
    [cell getDate:model andNum:indexPath.row];
    
    return cell;
}


- (void)getInfo:(NSArray *)arr
{
    self.arr = arr;
    [self.tableView reloadData];
}
@end
